package cn.itcast.mq.helloworld;

import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class SpringAmqpTest1 {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 基本消息对列
     */
    @Test
    public void basic(){
        //消息对列
        String queue="basic.queue";
        //消息
        String message="基本消息对列basic";
        //发送请求
        rabbitTemplate.convertAndSend(queue,message);
    }

    /**
     * 工作消息多列
     */
    @Test
    public void word(){
        //对列名称
        String queue="word.queue";
        //消息
        String message="工作消息对列work";
        //发送请求
        for (int i = 0; i < 40; i++) {
            rabbitTemplate.convertAndSend(queue,message);
        }
    }

    /**
     * 发布订阅之广播
     */
    @Test
    public void fanout(){
        //对列名称
        String exchangeName="itcast.fanout";
        //消息
        String message="发布订阅之广播fanout";
        //发送请求
        rabbitTemplate.convertAndSend(exchangeName,"",message);
    }

    /**
     * 发布订阅之路由
     */
    @Test
    public void direct(){
        //对列名称
        String exchangeName="itcast.direct";
        //消息
        String message="发布订阅之路由direct";
        //发送请求
        rabbitTemplate.convertAndSend(exchangeName,"aa",message);
    }

    /**
     * 发布订阅之主题
     */
    @Test
    public void topic(){
        //多列名称
        String exchangeName="itcast.topic";
        //消息
        String message="主题topic";
        //发送请求
        //rabbitTemplate.convertAndSend(exchangeName,"aa.#",message);
        rabbitTemplate.convertAndSend(exchangeName,"#.bb",message);

    }
}
